import Vue from 'vue'
import VueRouter from 'vue-router'
import Router from 'vue-router'
const Register = () => import('../views/Register.vue')
const Index = () => import('../views/index.vue')
const Login = () => import('../views/Login.vue')
const UserList = () => import('../views/UserList.vue')
const FoodList = () => import('../views/FoodList.vue')
const FoodClass = () => import('../views/FoodClass.vue')
const MapView = () => import('../views/MapView.vue')
const home = () => import('../views/home.vue')
Vue.use(Router)

const routes = [
  {
    path: '/',
    meta: {
      title: '登录'
    },
    component: Login
  },
  {
    path: '/index',
    redirect: "/index/home"
  },
  {
    path: '/Register',
    meta: {
      title: '注册'
    },
    component: Register
  },
  {
    path: '/index',
    meta: {
      title: '首页'
    },
    component: Index,
    children: [
      {
        path: 'home',
        component: home
      },
      {
        path: 'userlist',
        meta: {
          title: '用户列表'
        },
        component: UserList
      },
      {
        path: 'foodlist',
        meta: {
          title: '商品列表'
        },
        component: FoodList
      },
      {
        path: 'foodclass',
        meta: {
          title: '商品分类'
        },
        component: FoodClass
      },
      {
        path: 'mapView',
        meta: {
          title: '销量分析'
        },
        component: MapView
      }
    ]
  }
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//设置全局守卫
router.beforeEach((to, from, next) => {
  console.log(to);
  document.title = to.matched[0].meta.title;
  next()
})
export default router
